package com.yin.myproject.demo;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Created by Eason on 2017/7/5.
 */
public class Demo01 {
    public static void main(String[] args) throws SchedulerException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        //定义一个任务并绑定到具体的任务实例
        JobDetail job = newJob(MyJob.class)
                .withIdentity("job1", "group1")
                .build();

        //定义触发器
        Trigger trigger = newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(40)
                        .repeatForever())
                .build();

        //绑定任务和触发器
        scheduler.scheduleJob(job, trigger);

        scheduler.start();
    }
}

